var KeFuServer = (function ($) {
	var defaults = {};

	var soundSrc = {
		online: '../easy-chat/asset/sound/online.mp3',
		newMessage: '../easy-chat/asset/sound/newmessage.mp3'
	};

	function Module(options) {
		this.options = options ? $.extend(defaults, options) : defaults;
		this.socketModule = null;
		this.socket = null;
		this.ui = new KeFuServerUI();
		this.admin = new Admin();
		this.storage = new Storage();
		this.callerManager = new callerManager(this);
		this.sound = new Sound();
		this.notifyTimer = null;
		this.notify = null;
		this.operateFlag = 0; //当前页面无操作的标记
		this.unreadMessageNumber = 0;

		this.passToDialog = null; // 转接对话框
		if (!this.options.validateUrl) {
			console.log('帐号验证地址未设置');
			return false;
		}
		this.init();
	}

	Module.prototype.init = function () {
		this.getAdminInfo();
	};

	/**
	 * 恢复上一次对话
	 */
	Module.prototype.restore = function () {
		this.callerManager.restore();
	};

	Module.prototype.connectSocket = function () {
		this.socketModule = new KeFuServerSocket('/kefu');
		this.socket = this.socketModule.handle;
		this.listenTasks();
	};

	Module.prototype.getAdminInfo = function () {
		var me = this,
			url = me.options.validateUrl;
		// 验证客服人员信息
		$.ajax({
			url: url,
			dataType: 'json',
			success: function (resp) {
				// 通过验证后，将用户数据发送到socket。比对客服人员信息，通过验证后，获取
				// 在线客服列表、在线用户列表。列表内容包括：用户名、用户ID、用户角色、在线状态
				// 、开始通话时间、最后一次通话时间
				if (resp.user_id && resp.token) {
					me.connectSocket();
					var obj = {user_id: resp.user_id, token: resp.token};
					me.socketModule.getKeFuData(JSON.stringify(obj));
					me.ui.initView();
					me.bindCallerLi();

					me.sound.init();
					me.initNotify();
					me.bindNotify();
				}
			}
		});
	};

	// 需要监听的任务
	Module.prototype.listenTasks = function () {
		var me = this;
		//客服接入
		me.socket.on('welcome', function (jo) {
			if (jo.self) {
				var sf = jo.self,
					uo = {};
				uo.uid = sf.uid;
				uo.join_id = sf.join_id;
				uo.username = sf.username;
				uo.access_time = Date.now();
				uo.role = 9;
				uo.job_number = sf.job_number;
				me.ui.adminJoinId = sf.join_id;
				me.admin.setAdminInfo(uo);
				me.restore();
			}
			if (jo.message) {
				me.setSystemMessage(jo.message);
			}
		});

		// 监听服务器发来的访客接入请求
		me.socket.on('inform', function (jo) {
			if ($.isPlainObject(jo)) {
				me.confirmConversation(jo);
			}
		});

		// 预读访客消息
		me.socket.on('prefetch', function (jo) {
			if (jo) {
				me.ui.callerMessagePrefetch(jo);
			}
		});

		// 服务器响应获取用户列表的请求
		me.socket.on('userListResponded', function (jo) {
			if (jo) {
				var html = me.buildPassToContent(jo);
				me.passToDialog.content(html);
			}
		});

		// 监听其它客服转接过来的对话
		me.socket.on('requestHandover', function (jo) {
			var title = '来自客服"' + jo.fromUsername + '"的转接请求';
			if (jo) {
				var timer = null;
				var content = '<p style="color:#888">访客：' + jo.callerName + '</p><p style="color:#888;margin-bottom:10px">附加消息：</p><div style="text-indent:2em">' + jo.msg + '</div>';
				var d = dialog({
					title: title,
					width: 400,
					content: content,
					okValue: '接受',
					cancelValue: '拒绝',
					ok: function () {
						jo.isAgree = 1;
						me.socket.emit('requestHandoverResp', jo);
						me.setNewCaller(jo.userInfo);
						clearInterval(timer);
					},
					cancel: function () {
						jo.isAgree = 0;
						me.socket.emit('requestHandoverResp', jo);
						clearInterval(timer);
					}
				});
				d.showModal();
				var timeCount = 30;
				timer = setInterval(function () {
					if (timeCount > 0) {
						d.statusbar('<span style="color:#f60">' + timeCount + '</span> 秒后自动关闭');
						timeCount--;
					} else if (timeCount == 0) {
						d.close().remove();
					}
				}, 1000);
			}
		});

		me.socket.on('controller', function (jo) {
			if (jo && jo.action && me[jo.action]) {
				me[jo.action].call(me, jo);
			}
		});
	};

	// 创建转接对话框中的内容，转接人员列表，和附加消息
	Module.prototype.buildPassToContent = function (adminList) {
		var html = '';
		if ($.isPlainObject(adminList)) {
			var me = this;
			var fromJoinId = me.admin.join_id;
			$.each(adminList, function (k, v) {
				if (v.join_id != fromJoinId) {
					html = '<li><input type="radio" name="toJoinId" value="' + v.join_id + '">' + v.user_name + '</li>';
				}
			});

			if (html == '') {
				html = '<div style="height:120px;line-height:120px;text-align:center;">当前没有其它客服在线</div>';
			} else {
				var tmp = '<form action="javascript:;" class="passToForm" id="passToForm"><ul class="passToUl">';
				tmp += html;
				tmp += '</ul>';
				tmp += '<div class="passTomMsgBox"><label>附加消息：</label><div><textarea name="msg" id="passToMsg" class="passToMsg"></textarea></div></div>';
				tmp += '</form>';
				html = tmp;
			}
		} else {
			html = '<div style="height:120px;line-height:120px;text-align:center;">当前没有其它客服在线</div>';
		}
		return html;
	};

	// 设置系统消息
	Module.prototype.setSystemMessage = function (message) {
		var li = '<li class="smLi">';
		li += message;
		li += '</li>';
		this.ui.$sysMsgList.append(li);
	};

	// 监听从访客发来的消息
	Module.prototype.getMessage = function (jo) {
		var me = this;
		me.sound.play(soundSrc.newMessage);
		me.setMessage(jo, jo.from);

		if(me.operateFlag == 1) {
			me.triggerNotify();
		}
	};

	// 设置消息
	Module.prototype.setMessage = function (jo, callerJoinId) {
		var me = this,
			adminJoinId = me.admin.join_id,
			$msgList = me.ui.getDialogElement(callerJoinId, '$msgList');
		// 如果对话框已经初始化，直接将消息添加到消息列表
		if ($msgList) {
			var $lTL = $msgList.find('.ecTimeLi:last'),
				endtime,
				timeSpan = 60 * 5,
				isNeedTimeSplit = 1,
				msgFrom = jo.from,
				timestamp = jo.timestamp || parseInt((new Date()).getTime() / 1000);
			if (msgFrom === adminJoinId) { // 发送
				me.ui.clearMessageInput(callerJoinId);
			} else {
				$msgList.find('.preMsg').remove(); // 删除预监听的内容。
			}
			if ($lTL.size() > 0) {
				endtime = $lTL.data('mark');
				if (endtime && (timestamp < endtime + timeSpan)) {
					isNeedTimeSplit = 0;
				}
			}
			var liHtml = '';
			if (isNeedTimeSplit) {
				liHtml += me.buildTimeSplit(timestamp);
				me.appendToMessageList(liHtml, $msgList, callerJoinId);
			}
			me.appendToMessageList(jo, $msgList, callerJoinId);
		}

		// 如果对话框没有初始化，或者当前显示的访客对话框与当前需要设置的不是同一个访客，则需要在访客列表里设置相应的
		// 未读消息数量
		if (me.callerManager.topCallerJoinId != callerJoinId) {
			var num = me.callerManager.getCallerAttr(callerJoinId, 'num') || 0;
			num = parseInt(num) + 1;
			me.unreadMessageNumber += num; //设置未读消息的数量
			me.callerManager.setCallerAttr(callerJoinId, 'num', num);
			me.ui.setCallerUnreadNum(callerJoinId, num);
		}
	};


	Module.prototype.appendToMessageList = function (data, $msgList, callerJoinId) {
		var me = this,
			liHtml;
		if ($.isPlainObject(data)) {
			liHtml = me.ui.buildMessageHtml(data, me.admin.join_id);
		} else {
			liHtml = data;
		}
		$msgList.append(liHtml);
		me.ui.messageListScrollToBottom(callerJoinId);
	};

	// 弹出对话框，客服可选择是否与访客对话
	Module.prototype.confirmConversation = function (userInfo) {
		// 当值为1时，则弹出确认对话框
		var me = this;
		var isConfirm = $('#isConfirm').val();
		var content = '访客 <strong style="color: blue;font-weight: 900">';

		if (userInfo.uid > 0) {
			content += userInfo.username;
			content += '</strong> (会员 | ip:';
		}
		else {
			content += userInfo.username;
			content += '</strong> (游客 | ip:';
		}
		content += userInfo.ip;
		content += ') 请求与您对话！';

		var ro = {};
		ro.talk_id = userInfo.talk_id;
		ro.uid = userInfo.uid;
		ro.adminId = me.admin.uid;
		ro.caller_name = userInfo.username;
		ro.joinId = me.admin.join_id;
		ro.callerJoinId = userInfo.join_id;
		ro.csName = me.admin.job_number;
		ro.allocation_type = userInfo.allocation_type; // 确认与访客对话，当allocation_type=1时，是用户通过手动点击分组的方式请求的连接
		ro.ip = userInfo.ip;

		if (isConfirm == 1) {
			var d = dialog({
				title: '确认',
				content: content,
				okValue: '接受',
				cancelValue: '拒绝',
				ok: function () {
					me.agreeAnswer(ro, userInfo);
				},
				cancel: function () {
					ro.status = 0;
					me.replyCaller(ro);
				}
			});
			d.showModal();
		} else {
			me.agreeAnswer(ro, userInfo);
		}
	};

	// 同意应答访客
	Module.prototype.agreeAnswer = function (ro, userInfo) {
		var me = this;
		ro.status = 1; // 1 为接受，其它为拒绝
		ro.welcome = me.buildMessage('您好，【KACN客服平台】欢迎您的咨询！请问有什么可以帮助到您？', ro.callerJoinId, ro.talk_id);
		ro.caller = userInfo;
		//ro.welcome = me.buildMessage('您好，我是"' + me.admin.username + '"，很高兴为您服务！');
		/**
		 var ro = {
				adminId: 30,
				allocation_type: 1,
				csName: "0130号客服专员",
				callerJoinId: "u_62e3db9039ed50fee61b9500a70ad6fe",
				caller_name: "u55a36712298f8",
				ip: "127.0.0.1",
				joinId: "a30",
				status: 1,
				uid: 0,
				welcome: {
					from: "a30",
					id: "db5535f1-64e5-4a54-b2b2-d0f32ead5f64",
					message: "您好，【KACN客服平台】欢迎您的咨询！请问有什么可以帮助到您？",
					role: 9,
					time: "07-17 10:32:50",
					to: "u_62e3db9039ed50fee61b9500a70ad6fe",
					username: "0130号客服专员"
				}
			}
		 */
		me.replyCaller(ro);
		me.sound.play(soundSrc.online);
	};

	/**
	 * 在访客列表里添加新的访客
	 * @param userInfo
	 */
	Module.prototype.setNewCaller = function (userInfo) {
		var me = this;
		me.ui.setNewCaller(userInfo);
		me.callerManager.addCaller(userInfo);
		if (me.callerManager.topCallerJoinId == null) {
			me.initDialogWindow(userInfo);
		}
	};

	/**
	 * 创建发送给访客的消息对象
	 * @param msg
	 * @param callerJoinId
	 * @param talkId
	 * @returns {{}}
	 */
	Module.prototype.buildMessage = function (msg, callerJoinId, talkId) {
		var me = this,
			mo = {};
		mo.talk_id = talkId;
		mo.id = generateUUID();
		mo.from = me.admin.join_id;
		mo.to = callerJoinId;
		mo.username = me.admin.job_number;
		mo.message = msg;
		mo.time = friendlyTime();
		mo.role = me.admin.role;
		return mo;
	};

	// 显示聊天对话窗口
	Module.prototype.showDialog = function (callerJoinId) {
		var me = this;
		if (me.callerManager.topCallerJoinId != null) {
			me.ui.hideDialog(me.callerManager.topCallerJoinId);
		}
		me.callerManager.setTopCaller(callerJoinId);
		me.ui.showDialog(callerJoinId);
	};

	// 绑定发送按钮
	Module.prototype.bindDialogView = function (obj) {
		var me = this;
		obj.$sendMsgBtn.on('click', function () {
			me.sendMessage(obj);
		});

		//obj.$msgInput.on('keydown', function (evt) {
		//	var e = evt || window.event;
		//	if (e && e.keyCode == 13) {
		//		me.sendMessage(obj);
		//		e.preventDefault();
		//		return false;
		//	}
		//});

		obj.editor.addListener('keydown', function (type, e) {
			var keyCode = e.keyCode || e.which;
			if(keyCode == 13) {

				console.log(obj.editor);
				me.sendMessage(obj);
				e.preventDefault();
				return false;
			}
		});

	};

	Module.prototype.sendMessage = function (obj) {
		var me = this,
			callerJoinId = obj.joinId,
			flag = me.callerManager.getCallerStatus(callerJoinId);
		if (flag == 1) {
			//var msg = obj.$msgInput.val();
			var msg = obj.editor.getContent();
			if (msg != '') {
				var mo = me.buildMessage(msg, obj.joinId, obj.talkId);
				me.setMessage(mo, mo.to);
				this.socketModule.sendMessage(mo);
			} else {
				me.showTip(obj.$sendMsgBtn[0], '消息内容不可为空！');
			}
		} else if (flag == 2) {
			me.showTip(obj.$sendMsgBtn[0], '该访客已经下线，无法发送消息');
		} else if (flag == 3) {
			me.showTip(obj.$sendMsgBtn[0], '该访客已经被转接到其它客服，无法发送消息');
		}
	};

	/**
	 * 答复系统是否同意应答访客
	 * @param resultObj
	 * {
	 *   adminId,
	 *   callerJoinId,
	 *   status // 1 为接受，其它为拒绝
	 * }
	 */
	Module.prototype.replyCaller = function (resultObj) {
		var me = this;
		me.socket.emit('replyCaller', resultObj);
	};

	Module.prototype.bindCallerLi = function () {
		var me = this;
		me.ui.$callerList.on('click', '.js-openDialog', function () {
			var $this = $(this),
				userInfo = $this.data('userinfo');
			if (userInfo && userInfo.join_id) {
				var callerJoinId = userInfo.join_id;
				if (callerJoinId != me.callerManager.topCallerJoinId) {
					if (!($('#' + callerJoinId).size() > 0)) {
						me.initDialogWindow(userInfo);
					}
					me.showDialog(callerJoinId);

					// 以下两行，是将未读消息数量标记为0
					me.unreadMessageNumber -= me.callerManager.getCallerAttr(callerJoinId, 'num');
					me.callerManager.setCallerAttr(callerJoinId, 'num', 0);
					me.ui.setCallerUnreadNum(callerJoinId, 0);

				}
			}
		});
	};

	Module.prototype.initDialogWindow = function (userInfo) {
		var me = this,
			obj = me.ui.initDialogWindow(userInfo);
		me.bindDialogView(obj);
		me.bindHandover(obj.$box, obj.joinId, userInfo.username);
		me.bindDisconnect(obj.$box, obj.joinId, userInfo.username);
		me.pullRecentMessage(obj.talkId, obj.joinId);


		me.callerManager.setCallerInfo(userInfo);

		me.showDialog(userInfo.join_id);
	};

	// 发送从服务器获取消息的请求
	Module.prototype.pullRecentMessage = function (talkId, callerJoinId) {
		var obj = {};
		obj.action = 'getRecentMessage';
		obj.talkId = talkId;
		obj.callerJoinId = callerJoinId;
		this.socket.emit('controller', obj);
	};

	// 响应服务器获取到的最近消息
	Module.prototype.pullRecentMessageResp = function (jo) {
		if (jo && jo.callerJoinId && jo.result) {
			var arr = jo.result;
			if ($.isArray(arr)) {
				var arrLen = arr.length;
				if (arrLen > 0) {
					this.showRecentMessageList(arr, jo.callerJoinId);

					// TODO
					//chatManager.markMsgStateToRead(myUID, jo.to_uid);
					//chatManager.setNewMsgNum(jo.to_uid, 0);
				}
			}
		}
	};

	// 显示最近的聊天记录
	Module.prototype.showRecentMessageList = function (arr, callerJoinId) {
		var me = this,
			$msgList = me.ui.getDialogElement(callerJoinId, '$msgList'),
			liHtmlA = '',
			liHtmlB = '',
			endtime = 0;
		var $fTL = $msgList.find('.ecTimeLi:first');
		if ($fTL.size() > 0) {
			endtime = $fTL.data('mark');
		}
		var gArr = me.groupMsgByTime(arr, endtime);
		gArr.reverse();
		if (gArr.length > 0) {
			$.each(gArr, function (k, v) {
				v.arr.reverse();
				if (v.flag > 0) { //在消息列表里有同一时间段的消息
					$.each(v.arr, function (k, row) {
						var co = me.getMessageObj(row);
						liHtmlA += me.ui.buildMessageHtml(co, me.admin.join_id);
					});
				} else {
					liHtmlB += me.buildTimeSplit(v.timestamp);
					$.each(v.arr, function (k, row) {
						var co = me.getMessageObj(row);
						liHtmlB += me.ui.buildMessageHtml(co, me.admin.join_id);
					});
				}
			});
			if (liHtmlA) {
				if ($fTL.size() > 0) {
					$fTL.after(liHtmlA);
				} else {
					$msgList.append(liHtmlA);
				}
			}
			if (liHtmlB) {
				var $hLi = $msgList.find('.ecGetHisLi');
				if ($hLi.size > 0) {
					$msgList.find('.ecGetHisLi').after(liHtmlB);
				} else {
					$msgList.append(liHtmlB);
				}
			}
		}
		$msgList.find('.tipbox').removeClass('loadding');
	};


	Module.prototype.buildTimeSplit = function (timestamp, txt) {
		var viewHtml = '<li class="msgLi ecTimeLi';
		if (txt) {
			viewHtml += ' spline';
		} else {
			txt = friendlyTime(timestamp);
		}
		viewHtml += '" data-mark="' + timestamp + '">';
		viewHtml += '<div class="timebox"><span class="tmstr">' + txt + '</span></div>';
		viewHtml += '</li>';
		return viewHtml;
	};

	Module.prototype.getMessageObj = function (row) {
		var mo = {};
		mo.id = row.chat_id;
		mo.join_id = row.join_id;
		mo.to_join_id = row.to_join_id;
		mo.message = row.message;
		mo.time = friendlyTime(row.send_time);
		mo.timestamp = row.send_time;

		if (mo.join_id == this.admin.join_id) {
			mo.username = this.admin.job_number;
		} else {
			mo.username = this.callerManager.getCallerAttr(mo.join_id, 'username');
		}
		return mo;
	};

	//将消息按时间分组, 给定的消息数组按send_time降序排列
	Module.prototype.groupMsgByTime = function (msgArr, endtime) {
		var _msgArr = [];
		var timeSpan = 60 * 5;
		var getTheGroup = function (timestamp) {
			var group = undefined;
			if (_msgArr.length > 0) {
				$.each(_msgArr, function (k, gro) {
					if (timestamp == gro.timestamp) {
						group = gro;
						return false;
					}
				});
			}
			return group;
		};
		var buildMsgArr = function (mo, flg) {
			var stime = endtime - timeSpan;
			if (mo.send_time > stime && mo.send_time <= endtime) {
				var obj = getTheGroup(endtime);
				if (obj !== undefined) {
					obj.arr.push(mo);
				} else {
					var _obj = {
						timestamp: endtime,
						arr: [mo],
						flag: flg
					};
					_msgArr.push(_obj);
				}
			} else {
				endtime = mo.send_time;
				buildMsgArr(mo, 0);
			}
		};

		if ($.isArray(msgArr) && msgArr[0] && msgArr[0]['send_time']) {
			endtime = endtime || 0;
			var flg = 1;
			if (endtime <= 0) { // 如果没有指定起始时间，则以消息的第一条时间为基础
				flg = 0;
				endtime = msgArr[0]['send_time'];
			}
			$.each(msgArr, function (k, mo) {
				buildMsgArr(mo, flg);
			});
		}
		return _msgArr;
	};

	Module.prototype.bindHandover = function ($elm, callerJoinId, callerName) {
		var me = this;
		// 从服务器获取用户列表
		if ($elm.attr('bind') != 1) {
			var cHtml = '<span class="ui-dialog-loading">努力加载中...</span>';
			$elm.find('.js-handover').on('click', function () {
				me.socket.emit('userList', 1);
				var d = dialog({
					id: 'passToDialog',
					width: 480,
					skin: 'passToDialog',
					title: '将访客转接给其它客服',
					content: cHtml,
					okValue: '确定转接',
					cancelValue: '取消',
					ok: function () {
						var fa = $('#passToForm').serializeArray();
						var sObj = {};
						$.each(fa, function (key, val) {
							sObj[val.name] = val.value;
						});

						// 如果可以获取到被转接的客服ID，则继续下一步，否则提示错误
						if (sObj.toJoinId) {
							sObj.fromJobNumber = me.admin.job_number;
							sObj.fromUsername = me.admin.username;
							sObj.fromJoinId = me.admin.join_id;
							sObj.callerJoinId = callerJoinId;
							sObj.callerName = callerName;
							me.socket.emit('passToService', sObj);
						}
					},
					cancel: function () {
						me.passToDialog = null;
					}
				});
				me.passToDialog = d;
				d.showModal();
				$elm.attr('bind', 1);
			});
		}
	};

	Module.prototype.bindDisconnect = function ($elm, callerJoinId, username) {
		var me = this;
		if ($elm.attr('bind') != 1) {
			$elm.find('.js-disconnect').on('click', function () {
				var d = dialog({
					id: 'disconnectDialog',
					width: 480,
					title: '断开连接',
					content: '是否立即与当前访客"'+username+'"断开连接？',
					okValue: '确定',
					cancelValue: '取消',
					ok: function () {
						var obj = {};
						obj.action = 'offlineCaller';
						obj.callerJoinId = callerJoinId;
						me.socket.emit('controller', obj);
					},
					cancel: function () {}
				});
				d.showModal();
				$elm.attr('bind', 1);
			});
		}
	};

	Module.prototype.showTip = function (elm, msg, type) {
		var cls = 'ballonToolTip';
		if (type == 'warn') {
			msg = '<i class="warningTipIcon"></i>' + msg;
			cls += ' text-blue';
		}
		var d = dialog({
			skin: cls,
			content: msg,
			quickClose: true// 点击空白处快速关闭
		});
		d.show(elm);
	};

	// 与某访客断开连接
	Module.prototype.setCallerStatus = function (obj) {
		var me = this,
			callerJoinId = obj.callerJoinId;
		me.callerManager.setCallerStatus(callerJoinId, obj.flag);
	};

	/**
	 * 获取访客是否在线
	 * @param callerJoinId
	 */
	Module.prototype.getCallerStatus = function (callerJoinId) {
		var oGet = {};
		oGet.action = 'getCallerStatus';
		oGet.callerJoinId = callerJoinId;
		oGet.joinId = this.admin.join_id;
		this.socket.emit('controller', oGet);
	};

	/**
	 * 服务器端返回访客响应客服
	 * @param jo
	 */
	Module.prototype.getCallerStatusResponded = function (obj) {
		if (obj && obj.callerJoinId && obj.serviceId) {
			var me = this;
			if (obj.serviceId == me.admin.join_id) { // 判断访客当前对话的客服与发送请求的客服是否为同一人
				me.callerManager.updateCallerStatus(obj);
			}
		}
	};

	/**
	 * 客服拒绝转接
	 * @param jo
	 */
	Module.prototype.rejectHandover = function (obj) {
		if (obj && obj.callerJoinId) {
			var msg = '客服拒绝了接收' + obj.callerName;
			var d = dialog({
				title: '消息',
				content: msg,
				okValue: '知道了',
				ok: function () {
				}
			});
			d.showModal();
		}
	};

	Module.prototype.bindNotify = function () {
		var me = this;
		$(window).on('mouseover', function() {
			if(me.notifyTimer) {
				me.operateFlag = 0;
				clearTimeout(me.notifyTimer);
				if(me.notify) {
					me.notify.faviconClear();
					me.notify.clearTimer();
				}
			}

			me.notifyTimer = setTimeout(function() {
				me.operateFlag = 1;
			}, 30000);
		});
	};

	Module.prototype.triggerNotify = function() {
		var me = this;
		if(me.unreadMessageNumber) {
			me.notify.setFavicon(me.unreadMessageNumber);
		}
		me.notify.notify({
			title: "通知！",
			body: '您有新短消息'
		});
		me.notify.setTitle(true).player();
	};

	Module.prototype.initNotify = function () {
		this.notify = new iNotify({
			message: '来消息了。',//标题
			effect: 'flash', // flash | scroll | favicon 闪烁还是滚动
			//可选播放声音
			audio: {
				//可以使用数组传多种格式的声音文件
				file: '../easy-chat/asset/sound/newmessage.mp3'
			},
			//标题闪烁，或者滚动速度
			interval: 1000,
			//可选，默认绿底白字的  Favicon
			updateFavicon: {
				// favicon 字体颜色
				textColor: "#fff",
				//背景颜色，设置背景颜色透明，将值设置为“transparent”
				backgroundColor: "#ea6153"
			}
		});
	};

	return Module;
})(jQuery);